home *** CD-ROM | disk | FTP | other *** search
/ bioinformatics.org / bioinformatics.org_software.tar / www.bioinformatics.org / download / ecell2 / ecell220setup.exe / {app} / standard / SRCJ / Preference.java < prev    next >
Text File  |  2002-05-13  |  4KB  |  135 lines

  1. /**
  2.  * title:     Preference class (Preference.java)<p>
  3.  * description  : Preference window class<p>
  4.  * Copyright (C) 1996-2001 Keio University <p>
  5.  * Copyright (C) 1998-2001 Japan Science and Technology Corporation (JST)<p>
  6.  *               GNU General Public Licence <p>
  7.  * Division:     Mitsui Knowledge Industry Co. Ltd. Bioscience division <p>
  8.  * Version :     $Id: Preference.java,v 1.7 2002/05/13 00:23:04 ota Exp $ <p>
  9.  */
  10.  
  11. /**
  12.  * title :     Preference<p>
  13.  * description :         Preference Window<p>
  14.  * @author Xiangdong Zheng
  15.  * @version 1.0
  16.  */
  17. package ecell;
  18. import javax.swing.*;
  19. import java.awt.event.*;
  20.  
  21. import java.awt.BorderLayout;
  22. import java.awt.*;
  23.  
  24.  
  25. /**
  26.  * Preference window class
  27.  * @author      XD.Zheng
  28.  * @version     1.0
  29.  * @since       JDK1.2.2
  30.  */
  31.  
  32. public class Preference extends JDialog
  33. {
  34.     JPanel jp1 = new JPanel();
  35.     JPanel jp2 = new JPanel();
  36.     JLabel label1 = new JLabel("Step interval:  ");
  37.     JLabel label2 = new JLabel("Update interval:");
  38.     JTextField text1 = new JTextField(70);
  39.     JTextField text2 = new JTextField(70);
  40.     JButton buttonOk = new JButton("Ok");
  41.     JButton buttonClose = new JButton("CANCEL");
  42.  
  43.     /**
  44.      *CtrollorPanel
  45.      */
  46.     MainWindow window ;
  47.  
  48.     /**
  49.      *Constructor
  50.      *@param owner      Ctrollor Panel
  51.      */
  52.     public Preference(MainWindow owner) {
  53.  
  54.         super((Frame)owner,"Preferences",true);
  55.         this.window=owner;
  56.         jp1.setLayout(new GridLayout(2,2));
  57.         text1.setSize(70,30);
  58.         text2.setSize(70,30);
  59.         jp1.add(label1);
  60.         jp1.add(text1);
  61.         jp1.add(label2);
  62.         jp1.add(text2);
  63.         
  64.         // 2001.12.25 for ECELL2.2
  65.         //text1.setText(""+ window.df.getPreferenceStep());
  66.         //text2.setText(""+window.df.getPreferenceUpdate());
  67.         text1.setText( "" + window.engine.getPreferenceStep() );
  68.         text2.setText( "" + window.engine.getPreferenceUpdate() );
  69.         
  70.         jp2.setLayout(new FlowLayout(0,2,2));
  71.         buttonOk.addActionListener(actionListener);
  72.         buttonClose.addActionListener(actionListener);
  73.  
  74.         jp2.add(buttonOk);
  75.         jp2.add(buttonClose);
  76.         this.getContentPane().add(jp1,"Center");
  77.         this.getContentPane().add(jp2,"South");
  78.         this.addWindowListener(wListener);
  79.         this.setLocation(250,200);
  80.     }
  81.  
  82.     /**
  83.      * Instance of actionListener
  84.      */
  85.     ActionListener actionListener = new ActionListener() {
  86.         public void actionPerformed(ActionEvent e) {
  87.             if(e.getSource()== buttonOk){
  88.                 try{
  89.                     double step = Double.parseDouble(text1.getText().trim());
  90.                     int    update = Integer.parseInt(text2.getText().trim());
  91.                     
  92.                     // 2001.12.25 for ECELL2.2
  93.                     //window.df.setPreference(step,update);
  94.                     window.engine.setPreference( step, update );
  95.                     
  96.                     Preference.this.setVisible(false);
  97.                     Preference.this.dispose();
  98.                 }catch(NumberFormatException ex){
  99.                     Object message ="No input or input error!!";
  100.                     String title ="Preference";
  101.                     int messageType = JOptionPane.ERROR_MESSAGE;
  102.                     JOptionPane.showMessageDialog(Preference.this,message,
  103.                                                                        title,messageType);
  104.                 }    catch(Exception ex){
  105.                     window.messageWindow.setErrorMessage( ex );
  106.                 }
  107.             }
  108.  
  109.             if(e.getSource()== buttonClose){
  110.                 Preference.this.setVisible(false);
  111.                 Preference.this.dispose();
  112.             }
  113.  
  114.         }
  115.     }; 
  116.  
  117.     /**
  118.      * Instance of WindowListener
  119.      */
  120.     WindowListener wListener = new WindowListener() {
  121.         public void windowOpened(WindowEvent e){}
  122.         public void windowClosing(WindowEvent e){
  123.             Preference.this.setVisible(false);
  124.             Preference.this.dispose();
  125.  
  126.         }
  127.         public void windowClosed(WindowEvent e){}
  128.         public void windowIconified(WindowEvent e){}
  129.         public void windowDeiconified(WindowEvent e){}
  130.         public void windowActivated(WindowEvent e){}
  131.         public void windowDeactivated(WindowEvent e){}
  132.     };
  133.  
  134. }
  135.